package com.personnel.servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.personnel.entity.LzUser;
import com.personnel.service.ILzUserService;
import com.personnel.service.LzUserService;

/**
 * Servlet implementation class AddLzUserServlet
 */
@WebServlet("/addlz.do")
public class AddLzUserServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddLzUserServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("utf-8");
		
		String y_id = request.getParameter("y_id");
		String ygbh = request.getParameter("ygbh");
		String ygxm = request.getParameter("ygxm");
		String rzrq = request.getParameter("rzrq");
		String lzrq = request.getParameter("lzrq");
		String lzyy = request.getParameter("lzyy");
		String lzqx = request.getParameter("lzqx");
		String rck = request.getParameter("rck");
		
		LzUser x = new LzUser();
		
		x.setY_id(Integer.parseInt(y_id));
		x.setYgbh(Integer.parseInt(ygbh));
		x.setYgxm(ygxm);
		x.setRzrq(rzrq);
		x.setLzrq(lzrq);
		x.setLzyy(lzyy);
		x.setLzqx(lzqx);
		x.setRck(Integer.parseInt(rck));
		
		ILzUserService service = new LzUserService();
		try {
			boolean isOkay = service.addLzUser(x);
			if(isOkay) {
				System.out.println("成功");
				response.sendRedirect("lz.do");
				
			}else {
				System.out.println("Oh NO~");
				response.sendRedirect("module2/lizhibiao.jsp");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
